/*
 * rx_functions.h.h
 * Created on August 5, 2005; 5:05 PM
 * by vramadurai
 */
#ifndef _RX_FUNCTIONS_H_
#define _RX_FUNCTIONS_H_

#include "HsTypes.h"

#define WRITE_STATUS(x,y)	//(*(volatile unsigned*)(x) = (y))

#define	ABS(X)	(((X) >= 0)? (X): -(X))

void find_latency(struct HS_Phy11bStr  *HS_Phy11bPtrTh);

void sync_on_dma(hs_int32_t  siInitAddrI, hs_int32_t  blocks);
void set_iq_buffer_ptr(struct HS_Phy11bStr * HS_Phy11bPtrTh, unsigned int iaddr, unsigned int qaddr);
void stop_rxiqdma();
void start_iqdma(struct HS_Phy11bStr * HS_Phy11bPtrTh, hs_int16_t *pssGlobalBufI, hs_int16_t *pssGlobalBufQ);

void rx_copysamps32_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysamps88_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysamps16_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysampsN_PRE_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysamps22_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysamps44(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );

void rx_copysamps14_update(
                    struct HS_Phy11bStr * HS_Phy11bPtrTh,
                    hs_int16_t * restrict ssInI,
                    hs_int16_t * restrict ssInQ
                );


void
despread_rpu(
            short * restrict ssInI,
            short * restrict ssInQ,
            short * restrict psUpSampBarkerSeq,
            short * ssRxSymbI,
            short * ssRxSymbQ
            );

void
rpu_iq48_copy(short * restrict piRdPtrI,
        short * restrict piRdPtrQ,
        short * restrict iq_scale,
        short * restrict iq_bias,
        short * restrict ssInI,
        short * restrict ssInQ
        );

void
rpu_iq32_copy(short * restrict piRdPtrI,
        short * restrict piRdPtrQ,
        short * restrict iq_scale,
        short * restrict iq_bias,
        short * restrict ssInI,
        short * restrict ssInQ
        );

void
get_prevsymbol(
                struct HS_Phy11bStr  *HS_Phy11bPtrTh,
                hs_int16_t *old_I,
                hs_int16_t *old_Q,
                hs_int16_t ssRxSymbI,
                hs_int16_t ssRxSymbQ
              );

void differential(hs_int16_t *ssRxSymbI, hs_int16_t *ssRxSymbQ, hs_int16_t old_I, hs_int16_t old_Q);

hs_int32_t rx_despread(hs_int16_t * restrict psUpSampBarkerSeq, hs_int16_t * restrict piRdPtr);
void init_rx(struct HS_Phy11bStr *HS_Phy11bPtrTh);
void init_global_buffers(struct HS_Phy11bStr *HS_Phy11bPtrTh);
void print_rx_stats(struct HS_Phy11bStr * HS_Phy11bPtrMain);

void copy_wrapped_data_44(
                        hs_int16_t  * restrict piRdPtr,
                        hs_int16_t  * restrict piStartPtr,
                        hs_int16_t  * restrict ssIn,
                        hs_int32_t  siOffset
                    );

void copy_wrapped_data(
                        hs_int16_t  *piRdPtr,
                        hs_int16_t  * restrict piStartPtr,
                        hs_int16_t  * restrict ssIn,
                        hs_int32_t  siOffset
                    );

void copy_wrapped_data_16(
                        hs_int16_t  *piRdPtr,
                        hs_int16_t  * restrict piStartPtr,
                        hs_int16_t  * restrict ssIn,
                        hs_int32_t  siOffset
                    );
#endif
